#pragma once

namespace Engine
	{
	namespace Pattern
		{
		template <class Type>
		class Singleton
			{
			protected:
				static Type *instance;
			public:
				Singleton();
				virtual ~Singleton();
				static Type* getInstance();
				//static void release();
			};
		template<class Type>
		Type* Singleton<Type>::instance = nullptr;

		template<class Type>
		Singleton<Type>::Singleton()
			{
			if(!instance)
				instance = static_cast<Type*>(this);
			}

		template<class Type>
		Singleton<Type>::~Singleton()
			{
			instance = 0;
			}

		template<class Type>
		Type* Singleton<Type>::getInstance()
			{
			if(!instance)
				instance = new Type;
			return instance;
			}

		/*template<class Type>
		void Singleton<Type>::release()
			{
			if(instance)
				delete instance;
			}*/
		}
	};